
import { ESGeoExtrudedPolygon } from "earthsdk3";
import { UeESGeoPolygon } from "../UeESGeoPolygon";
import { ESUeViewer } from "../../../ESUeViewer";
import { createNextAnimateFrameEvent } from "xbsj-base";

export class UeESGeoExtrudedPolygon extends UeESGeoPolygon<ESGeoExtrudedPolygon> {
    static override readonly type = this.register("ESUeViewer", ESGeoExtrudedPolygon.type, this);
    constructor(sceneObject: ESGeoExtrudedPolygon, ueViewer: ESUeViewer) {
        super(sceneObject, ueViewer);

        const viewer = ueViewer.viewer;
        if (!viewer) {
            console.warn(`viewer is undefined!`);
            return;
        }
        const update = () => {
            viewer.callUeFunc({
                f: 'update',
                p: {
                    id: sceneObject.id,
                    height: sceneObject.height ?? ESGeoExtrudedPolygon.defaults.height,
                    extrudedHeight: sceneObject.extrudedHeight ?? ESGeoExtrudedPolygon.defaults.extrudedHeight,
                    perPositionHeight: sceneObject.perPositionHeight ?? ESGeoExtrudedPolygon.defaults.perPositionHeight,
                }
            })
        };
        const updateEvent = this.disposeVar(createNextAnimateFrameEvent(
            sceneObject.heightChanged,
            sceneObject.extrudedHeightChanged,
            sceneObject.perPositionHeightChanged
        ));
        this.dispose(updateEvent.disposableOn(update));
        this.dispose(sceneObject.createdEvent.disposableOn(update));

    }
}